from django.db import models
import os
# Create your models here.
"""
class Teacher(models.Model):
    Name = models.CharField(max_length=100)
    Email = models.EmailField(max_length=50)
    
class TA(models.Model):
    Name = models.CharField(max_length=100)
    Email = models.EmailField()
    course = models.ForeignKey(Course)
"""

def get_file_path(instance, filename):
    return os.path.join('files', str(instance.id))

class Grader(models.Model):
    Name = models.CharField(max_length=100)
    Email = models.EmailField()
    Type = models.CharField(max_length=10)
    
class Student(models.Model):
    Name = models.CharField(max_length=100)
    RollNo = models.CharField(max_length=20)
    Email = models.EmailField(max_length=50)

class Course(models.Model):
    CourseNo = models.CharField(max_length=30)
    Name = models.CharField(max_length=40)
    SubEmail = models.EmailField(max_length=40)
    SubPassword = models.TextField()
    Graders = models.ManyToManyField(Grader)
    Students = models.ManyToManyField(Student)
    Year = models.IntegerField()
    Semester = models.CharField(max_length=10)
    
class Assignment(models.Model):
    Name = models.CharField(max_length=100)
    SubjectLine = models.CharField(max_length=50)
    StartDateTime = models.DateTimeField()
    EndDateTime = models.DateTimeField()
    course = models.ForeignKey(Course)

class Question(models.Model):
    ParentQuestion = models.ForeignKey('self', null=True)
    assignment = models.ForeignKey(Assignment)
    QNo = models.IntegerField()
    MaxMarks = models.FloatField()
    
    
class QuestionGrade(models.Model):
    submission = models.ForeignKey('Submission')
    question = models.ForeignKey(Question)
    Marks = models.FloatField()
    
class Submission(models.Model):
    student = models.ForeignKey(Student)
    assignment = models.ForeignKey(Assignment)
    grader = models.ForeignKey(Grader, null=True)
    Timestamp = models.DateTimeField()
    Comment = models.TextField()
    Status = models.CharField(max_length=10)
    fileSub = models.FileField(upload_to=get_file_path, null=True)
    BonusPenaltyType = models.CharField(max_length=1)
    BonusPenaltyValue = models.FloatField()
